Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
ms-rest-azure
Advanced tools
Client Runtime for Node.js Azure client libraries generated using AutoRest
The ms-rest-azure npm package is a library for Node.js that provides authentication and client creation functionalities for Azure services. It simplifies the process of interacting with Azure resources by handling the complexities of authentication and service client management.
Authentication with Azure
This feature allows you to authenticate with Azure using a service principal. The code sample demonstrates how to log in using a client ID, secret, and domain.
const msRestAzure = require('ms-rest-azure');
msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain, (err, credentials) => {
if (err) return console.log(err);
console.log('Authenticated successfully');
});
Creating a Resource Management Client
This feature allows you to create a client for managing Azure resources. The code sample shows how to create a Resource Management Client after authenticating with Azure.
const msRestAzure = require('ms-rest-azure');
const AzureArmResource = require('azure-arm-resource');
msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain, (err, credentials) => {
if (err) return console.log(err);
const client = new AzureArmResource.ResourceManagementClient(credentials, subscriptionId);
console.log('Resource Management Client created successfully');
});
Listing Resource Groups
This feature allows you to list all resource groups in a subscription. The code sample demonstrates how to list resource groups using the Resource Management Client.
const msRestAzure = require('ms-rest-azure');
const AzureArmResource = require('azure-arm-resource');
msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain, (err, credentials) => {
if (err) return console.log(err);
const client = new AzureArmResource.ResourceManagementClient(credentials, subscriptionId);
client.resourceGroups.list((err, result) => {
if (err) return console.log(err);
console.log('Resource Groups:', result);
});
});
The azure-sdk-for-js is a collection of libraries for various Azure services. It provides more modern and modular packages compared to ms-rest-azure, allowing you to include only the specific services you need. It also supports the latest Azure features and improvements.
The azure-arm-resource package is specifically designed for managing Azure resources. It provides functionalities similar to ms-rest-azure but focuses solely on resource management. It can be used in conjunction with ms-rest-azure for authentication.
The azure-storage package is designed for interacting with Azure Storage services. While ms-rest-azure provides general authentication and client creation, azure-storage focuses on storage-specific operations like managing blobs, queues, and tables.
Infrastructure for error handling, tracing, and http client pipeline configuration. Required by nodeJS Azure client libraries, generated using AutoRest.
npm install ms-rest-azure
var msrestAzure = require('ms-rest-azure');
It provides a url and code that needs to be copied and pasted in a browser and authenticated over there. If successful, the user will get a DeviceTokenCredentials object.
var someAzureServiceClient = require('azure-arm-someService');
msRestAzure.interactiveLogin(function(err, credentials) {
if (err) return console.log(err);
var client = new someAzureServiceClient(credentials, 'your-subscriptionId');
client.someOperationGroup.method(param1, param2, function(err, result) {
if (err) return console.log(err);
return console.log(result);
});
});
This mechanism will only work for organizational ids and ids that are not 2FA enabled. Otherwise it is better to use the above mechanism (interactive login).
var someAzureServiceClient = require('azure-arm-someService');
msRestAzure.loginWithUsernamePassword(username, password, function(err, credentials) {
if (err) return console.log(err);
var client = new someAzureServiceClient(credentials, 'your-subscriptionId');
client.someOperationGroup.method(param1, param2, function(err, result) {
if (err) return console.log(err);
return console.log(result);
});
});
If you need to create an automation account for non interactive or scripting scenarios then please take a look at the documentation over here. Once you have created a service principal you can authenticate using the following code snippet.
var someAzureServiceClient = require('azure-arm-someService');
msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain, function(err, credentials) {
if (err) return console.log(err);
var client = new someAzureServiceClient(credentials, 'your-subscriptionId');
client.someOperationGroup.method(param1, param2, function(err, result) {
if (err) retutrn console.log(err);
return console.log(result);
});
});
This can be very useful in doing something custom or while debugging.
To find out the power of sendRequest(), please visit this link for detailed documentation of supported options while sending a request.
const msrest = require('ms-rest');
const msRestAzure = require('ms-rest-azure');
const AzureServiceClient = msRestAzure.AzureServiceClient;
const clientId = process.env['CLIENT_ID'];
const secret = process.env['APPLICATION_SECRET'];
const domain = process.env['DOMAIN']; //also known as tenantId
const subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'];
var client;
//an example to list resource groups in a subscription
msRestAzure.loginWithServicePrincipalSecret(clientId, secret, domain).then((creds) => {
client = new AzureServiceClient(creds);
let options = {
method: 'GET',
url: `https://management.azure.com/subscriptions/${subscriptionId}/resourcegroups?api-version=2016-09-01`,
headers: {
'user-agent': 'MyTestApp/1.0'
}
}
return client.sendRequest(options);
}).then((result) => {
console.dir(result, {depth: null, colors: true});
}).catch((err) => {
console.dir(err, {depth: null, colors: true});
});
FAQs
Client Runtime for Node.js Azure client libraries generated using AutoRest
The npm package ms-rest-azure receives a total of 195,752 weekly downloads. As such, ms-rest-azure popularity was classified as popular.
We found that ms-rest-azure demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.